package Vista;
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.BorderFactory;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JOptionPane;

import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.border.BevelBorder;

import Controlador.ContCategoria;
import Controlador.ContIngrexProd;
import Modelo.Conexion;
import Modelo.ModCategoria;
import Modelo.ModIngredientes;
import Modelo.ModProductos;
import Modelo.ModProdxIngre;

/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class IngrexProd extends javax.swing.JDialog {
	/**
	 * @uml.property  name="jLabel1"
	 * @uml.associationEnd  multiplicity="(1 1)"
	 */
	private JLabel jLabel1;
	/**
	 * @uml.property  name="jPanel1"
	 * @uml.associationEnd  multiplicity="(1 1)"
	 */
	private JPanel jPanel1;
	/**
	 * @uml.property  name="jLabel3"
	 * @uml.associationEnd  multiplicity="(1 1)"
	 */
	private JLabel jLabel3;
	/**
	 * @uml.property  name="jLabel4"
	 * @uml.associationEnd  multiplicity="(1 1)"
	 */
	private JLabel jLabel4;
	/**
	 * @uml.property  name="jLabel5"
	 * @uml.associationEnd  multiplicity="(1 1)"
	 */
	private JLabel jLabel5;
	/**
	 * @uml.property  name="jLabel6"
	 * @uml.associationEnd  multiplicity="(1 1)"
	 */
	private JLabel jLabel6;
	/**
	 * @uml.property  name="jButton1"
	 * @uml.associationEnd  multiplicity="(1 1)"
	 */
	private JButton jButton1;
	/**
	 * @uml.property  name="jButton5"
	 * @uml.associationEnd  multiplicity="(1 1)"
	 */
	private JButton jButton5;
	/**
	 * @uml.property  name="jButton4"
	 * @uml.associationEnd  multiplicity="(1 1)"
	 */
	private JButton jButton4;
	/**
	 * @uml.property  name="jTextField1"
	 * @uml.associationEnd  multiplicity="(1 1)"
	 */
	private JTextField jTextField1;
	/**
	 * @uml.property  name="jComboBox2"
	 * @uml.associationEnd  multiplicity="(1 1)"
	 */
	private JComboBox jComboBox2;
	/**
	 * @uml.property  name="jComboBox1"
	 * @uml.associationEnd  multiplicity="(1 1)"
	 */
	private JComboBox jComboBox1;
	/**
	 * @uml.property  name="jLabel2"
	 * @uml.associationEnd  multiplicity="(1 1)"
	 */
	private JLabel jLabel2;

	/**
	* Auto-generated Main method to display this JDialog
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				JFrame frame = new JFrame();
				IngrexProd inst = new IngrexProd(frame);
				inst.setVisible(true);
			}
		});
	}
	
	public IngrexProd(JFrame frame) {
		super(frame);
		initGUI();
	}
	
	private void initGUI() {
		try {
			{
				getContentPane().setLayout(null);
				this.addWindowListener(new WindowAdapter() {
					public void windowOpened(WindowEvent evt) {
						System.out.println("this.windowOpened, event="+evt);
						//TODO add your code for this.windowOpened
						new Conexion().llenarCombo(jComboBox1, "select \"Descripcion\" from \"Productos\" ");
						new Conexion().llenarCombo(jComboBox2, "select \"Descripcion\" from \"Ingredientes\" ");
						ContIngrexProd cIng = new ContIngrexProd(); 
						cIng.limpiar(jLabel5,jLabel6,jComboBox1,jComboBox2,jTextField1,jButton1,jButton4);

					}
				});
				{
					jLabel1 = new JLabel();
					getContentPane().add(jLabel1);
					jLabel1.setText("Registro de Ingredientes por Productos");
					jLabel1.setBounds(30, 50, 343, 28);
					jLabel1.setFont(new java.awt.Font("Segoe UI",1,18));
				}
				{
					jPanel1 = new JPanel();
					getContentPane().add(jPanel1);
					jPanel1.setBounds(30, 98, 380, 119);
					jPanel1.setBorder(BorderFactory.createEtchedBorder(BevelBorder.LOWERED));
					jPanel1.setLayout(null);
					{
						jLabel2 = new JLabel();
						jPanel1.add(jLabel2);
						jLabel2.setText("Producto:");
						jLabel2.setBounds(21, 15, 88, 25);
					}
					{
						jLabel3 = new JLabel();
						jPanel1.add(jLabel3);
						jLabel3.setText("Ingrediente:");
						jLabel3.setBounds(21, 48, 88, 25);
					}
					{
						jLabel4 = new JLabel();
						jPanel1.add(jLabel4);
						jLabel4.setText("Cantidad:");
						jLabel4.setBounds(21, 82, 88, 25);
					}
					{
						ComboBoxModel jComboBox1Model = 
							new DefaultComboBoxModel(
									new String[] { "Item One", "Item Two" });
						jComboBox1 = new JComboBox();
						jPanel1.add(jComboBox1);
						jComboBox1.setModel(jComboBox1Model);
						jComboBox1.setBounds(135, 15, 179, 24);
						jComboBox1.addActionListener(new ActionListener() {
							public void actionPerformed(ActionEvent evt) {
								System.out.println("jComboBox1.actionPerformed, event="+evt);
								//TODO add your code for jComboBox1.actionPerformed
								try
								{
								int n=Integer.parseInt( new Conexion().getCampo("Productos", "\"Descripcion\"='"+ jComboBox1.getSelectedItem() +"'").toString());
								jLabel5.setText(""+n);

								}
								catch(Exception e)
								{
									
								}							

							}
						});
						jComboBox1.addFocusListener(new FocusAdapter() {
							public void focusLost(FocusEvent evt) {
								System.out.println("jComboBox1.focusLost, event="+evt);
								//TODO add your code for jComboBox1.focusLost
							}
						});
					}
					{
						ComboBoxModel jComboBox2Model = 
							new DefaultComboBoxModel(
									new String[] { "Item One", "Item Two" });
						jComboBox2 = new JComboBox();
						jPanel1.add(jComboBox2);
						jComboBox2.setModel(jComboBox2Model);
						jComboBox2.setBounds(135, 48, 179, 24);
						jComboBox2.addActionListener(new ActionListener() {
							public void actionPerformed(ActionEvent evt) {
								System.out.println("jComboBox2.actionPerformed, event="+evt);
								//TODO add your code for jComboBox2.actionPerformed
								try
								{
								int n=Integer.parseInt( new Conexion().getCampo("Ingredientes", "\"Descripcion\"='"+ jComboBox2.getSelectedItem() +"'").toString());
								jLabel6.setText(""+n);

								}
								catch(Exception e)
								{
									
								}



								

							}
						});
					}
					{
						jTextField1 = new JTextField();
						jPanel1.add(jTextField1);
						jTextField1.setBounds(135, 83, 50, 22);
						jTextField1.addKeyListener(new KeyAdapter() {
							public void keyReleased(KeyEvent evt) {
								System.out.println("jTextField1.keyReleased, event="+evt);
								//TODO add your code for jTextField1.keyReleased
								
							}
						});
					}
					{
						jLabel5 = new JLabel();
						jPanel1.add(jLabel5);
						jLabel5.setText("jLabel5");
						jLabel5.setBounds(326, 18, 40, 21);
					}
					{
						jLabel6 = new JLabel();
						jPanel1.add(jLabel6);
						jLabel6.setText("jLabel6");
						jLabel6.setBounds(326, 50, 40, 22);
					}
				}
				{
					jButton1 = new JButton();
					getContentPane().add(jButton1);
					jButton1.setText("Incluir");
					jButton1.setBounds(84, 236, 77, 22);
					jButton1.setFont(new java.awt.Font("Segoe UI",0,9));
					jButton1.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent evt) {
							System.out.println("jButton1.actionPerformed, event="+evt);
							//TODO add your code for jButton1.actionPerformed
							ContIngrexProd cIng = new ContIngrexProd(); 
							cIng.guardar(jLabel5,jLabel6,jComboBox1,jComboBox2,jTextField1,jButton1,jButton4);
						}
					});
				}
				{
					jButton5 = new JButton();
					getContentPane().add(jButton5);
					jButton5.setText("Salir");
					jButton5.setBounds(290, 236, 69, 22);
					jButton5.setFont(new java.awt.Font("Segoe UI",0,9));
					jButton5.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent evt) {
							System.out.println("jButton5.actionPerformed, event="+evt);
							//TODO add your code for jButton5.actionPerformed
							dispose();
						}
					});
				}
				{
					jButton4 = new JButton();
					getContentPane().add(jButton4);
					jButton4.setText("Cancelar");
					jButton4.setBounds(160, 236, 77, 22);
					jButton4.setFont(new java.awt.Font("Segoe UI",0,9));
					jButton4.addActionListener(new ActionListener() {
						public void actionPerformed(ActionEvent evt) {
							System.out.println("jButton4.actionPerformed, event="+evt);
							//TODO add your code for jButton4.actionPerformed
							ContIngrexProd cIng = new ContIngrexProd(); 
							cIng.limpiar(jLabel5,jLabel6,jComboBox1,jComboBox2,jTextField1,jButton1,jButton4);
						}
					});
				}
			}
			this.setSize(450, 316);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

}
